<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:cu="http://apache.org/cocoon/counit" version="1.0">

  <!-- 
    remove whitespace from output and expected output if ignore-whitespace is true on the testcase. 
  
    Authors: Jan Willem Boer <janwillem@jwenr.nl>
  -->

  <xsl:template
    match="*[self::cu:output|self::cu:expect][parent::cu:testcase[not(@ignore-whitespace='false')]]">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="node()" mode="strip-whitespace"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="text()" mode="strip-whitespace">
    <xsl:value-of select="normalize-space(.)"/>
  </xsl:template>

  <xsl:template match="node()[not(self::text())]|@*" mode="strip-whitespace">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*" mode="strip-whitespace"/>
    </xsl:copy>
  </xsl:template>

  <!-- copy everything else -->
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
